#include<iostream>
#include<string>
using namespace std;
const int N = 1e3 + 10;
int f[N][N];
string s1, s2;
int n;
int main()
{
	cin >> n;
	cin >> s1 >> s2;
	s1 = " " + s1;
	s2 = " " + s2;
	int ma = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[j]) {
				f[i][j] = f[i - 1][j - 1] + 1;
				ma = max(f[i][j], ma);
			}
		}
	}
	cout << ma << endl;
	return 0;
}